﻿using Chaunce.FrameWork.NetCore.Chaunce.Utility.Helpers;
using Chaunce.FrameWork.NetCore.SysCore.Consts;
using Chaunce.FrameWork.NetCore.Utility.Exceptions;
using System;
using System.Collections.Generic;
using System.Text;

namespace Chaunce.FrameWork.NetCore.SysCore.Configuration
{
    public class ConnectionConfig
    {
        /// <summary>
        /// 数据库默认连接字符串
        /// </summary>
        public string DefaultConnection { get; set; }

        /// <summary>
        /// 解密后的连接字符串
        /// </summary>
        /// <returns></returns>
        public string DecryptDefaultConnection
        {
            get
            {
                try
                {
                    if (!string.IsNullOrEmpty(DefaultConnection))
                    {
                        return EncryptHelper.DESDecrypt(DefaultConnection, SystemConst.Chaunce_ENCRYPT_KEY);
                    }
                    return string.Empty;
                }
                catch (Exception ex)
                {
                    throw new ChaunceException("解密数据库连接字符串异常", ex);
                }
            }
        }
    }
}
